//
//  UIBarButtonItem+YCTools.m
//  Pods
//
//  Created by Apple on 2022/11/2.
//

#import "UIBarButtonItem+YCTools.h"
#import "UIButton+YCTools.h"
#import "UIImage+YCTools.h"

@implementation UIBarButtonItem (YCTools)

//+ (UIBarButtonItem *)blackBackButtonItemWithTarget:(id)target action:(SEL)seltor {
//    return [self BBIWithImage:[UIImage categoryImageWithName:@"icon_nav_back_black"] target:target action:seltor];
//}
//
//+ (UIBarButtonItem *)whiteBackButtonItemWithTarget:(id)target action:(SEL)seltor {
//    return [self BBIWithImage:[UIImage categoryImageWithName:@"icon_nav_back_white"] target:target action:seltor];
//}

+ (UIBarButtonItem *)BBIWithImage:(UIImage *)image target:(id)target action:(SEL)seltor {
    UIButton *btn = [UIButton buttonWithFrame:CGRectMake(0, 0, 44, 44) image:image target:target action:seltor];
    
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    return buttonItem;
}

+ (UIBarButtonItem *)BBIWithText:(NSString *)text color:(UIColor *)color font:(UIFont *)font target:(id)target action:(SEL)seltor {
    UIButton *btn = [UIButton buttonWithFrame:CGRectMake(0, 0, 44, 44) title:text titleColor:color font:font target:target action:seltor];
    
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    
    CGSize size = [btn sizeThatFits:CGSizeMake(CGFLOAT_MAX, 44)];
    btn.frame = CGRectMake(0, 0, size.width, 44);
    
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    return buttonItem;
}

+ (UIBarButtonItem *)BBIWithText:(NSString *)text
                           color:(UIColor *)color
                            font:(UIFont *)font
                     borderWidth:(CGFloat)borderWidth
                     borderColor:(UIColor *)borderColor
                           space:(CGFloat)space
                          target:(id)target
                          action:(SEL)seltor {
    UIButton *btn = [UIButton buttonWithFrame:CGRectMake(0, 0, 44, 44) title:text titleColor:color font:font target:target action:seltor];
    
    CGSize size = [btn sizeThatFits:CGSizeMake(CGFLOAT_MAX, 44)];
    btn.frame = CGRectMake(0, 0, size.width+space*2, 44);
    btn.layer.borderWidth = borderWidth;
    btn.layer.borderColor = borderColor.CGColor;
    
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    return buttonItem;
}

@end
